#include <stdio.h>
#include <stdint.h>
#include <stddef.h>

void increment(int *p);

int main(void)
{
    int num = 1;
    printf("num is %d\n", num);
    printf("num's address is %p\n", &num); // 0x7ffeef56b84c

    int *num_ptr = &num;
    intptr_t num_ptr_val = (intptr_t)num_ptr;
    printf("num's address integer is %ld\n", num_ptr_val); // 140732913858636

    increment(num_ptr);
    printf("num is %d\n", num);

    // 指针运算
    short *j = (short *)0x1234;
    j = j + 1;
    printf("%p\n", j); // 0x1236

    unsigned short *p1;
    unsigned short *p2;
    unsigned short *p3;

    unsigned short v1 = 1, v2 = 2, v3 = 3;
    p1 = &v1;
    p2 = &v2;
    p3 = &v3;

    printf("p1: %p\t p3: %p\n", p1, p3);

    // p3 = p2 + p1; // 两个指针相加非法

    ptrdiff_t pdiff = p1 - p3; // 两个指针相减合法，代表两个指针“距离”
    printf("%ld\n", pdiff);

    return 0;
}

void increment(int *p)
{
    // 通过指针进行取值和赋值
    *p = *p + 1;
}